// home/article/article.js
import http from '../../http'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    info: {}
  },
  timestampToYMDHMS(timestamp) {
    const date = new Date(timestamp);
    const year = date.getUTCFullYear();
    const month = ('0' + (date.getMonth() + 1)).slice(-2);
    const day = ('0' + date.getDate()).slice(-2);
    const hours = ('0' + date.getHours()).slice(-2);
    const minutes = ('0' + date.getMinutes()).slice(-2);
    const seconds = ('0' + date.getSeconds()).slice(-2);
    return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    let options = getCurrentPages()[getCurrentPages().length - 1].options
    console.log(options.id);
    http.post({
      url: '/Article/Detail',
      data: {
        id: options.id
      },
      then: (res) => {
        console.log('文章详情', res);
        let info = res.data.data
        info.time = this.timestampToYMDHMS(Number(info.createtime + '000'))
        this.setData({
          info: info
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})